package com.wanbatv.wangwangba.Pager;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;

import com.wanbatv.wangwangba.Login2Activity;
import com.wanbatv.wangwangba.R;
import com.wanbatv.wangwangba.util.FocusImageView;

/**
 * Created by 俞亚楠 on 2015/8/26.
 */
public class page3 extends RelativeLayout{
    private Context context;
    private AttributeSet attrs;
    public static FocusImageView dogtv_iv1;
    public static FocusImageView dogtv_iv2;
    public static FocusImageView dogtv_iv3;
    public static FocusImageView dogtv_iv4;
    public static FocusImageView dogtv_iv5;
    public static FocusImageView dogtv_iv6;
    public static boolean IS_F3=false;
    public page3(Context context){
        super(context);
        this.context=context;
    }
    public page3(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        this.attrs=attrs;

        LayoutInflater.from(context).inflate(R.layout.page3_view, this, true);
        dogtv_iv1=(FocusImageView)findViewById(R.id.dogtv_iv1);
        dogtv_iv2=(FocusImageView)findViewById(R.id.dogtv_iv2);
        dogtv_iv3=(FocusImageView)findViewById(R.id.dogtv_iv3);
        dogtv_iv4=(FocusImageView)findViewById(R.id.dogtv_iv4);
        dogtv_iv5=(FocusImageView)findViewById(R.id.dogtv_iv5);
        dogtv_iv6=(FocusImageView)findViewById(R.id.dogtv_iv6);
        dogtv_iv1.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F3=true;
                page2.IS_F2=false;
                page1.IS_F1=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
            }
        });
        dogtv_iv2.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F3=true;
                page2.IS_F2=false;
                page1.IS_F1=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
            }
        });
        dogtv_iv3.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F3=true;
                page2.IS_F2=false;
                page1.IS_F1=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
            }
        });

        dogtv_iv4.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F3=false;
                page2.IS_F2=false;
                page1.IS_F1=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
            }
        });
        dogtv_iv5.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F3=false;
                page2.IS_F2=false;
                page1.IS_F1=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
            }
        });
        dogtv_iv6.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F3=false;
                page2.IS_F2=false;
                page1.IS_F1=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
            }
        });

    }

    public void image_fangda(View v, boolean hasFocus){
        if (hasFocus) {
            v.getParent().bringChildToFront(v);

            Animation ani = AnimationUtils.loadAnimation(v.getContext(),
                    R.anim.bar_scale);
            ani.setFillAfter(true);

            v.startAnimation(ani);

        } else {
            Animation ani = AnimationUtils.loadAnimation(v.getContext(),
                    R.anim.bar_scale_in);
            ani.setFillAfter(true);
            v.startAnimation(ani);
        }
    }
}
